﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;
using Work.BL.Managers;
using Work.BL.POCOs;

namespace Work.UI.Web.MVC.Controllers
{
    public class SearchController : Controller
    {
        #region Fields

        private IVacancyManager _vacancyManager;

        #endregion

        #region Constructors

        public SearchController(IVacancyManager vacancyManager)
        {
            _vacancyManager = vacancyManager;
        }

        #endregion

        [HttpGet]
        public ActionResult Vacancy()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Vacancy(string text)
        {
            List<VacancyPOCO> res = _vacancyManager.Search(text);
            object o = res.ToArray();
            return Json(o);
        }

        [HttpGet]
        public ActionResult VacancyDetails(int id)
        {
            VacancyPOCO vacancyPoco =  _vacancyManager.GetVacancyById(id);
            
            return View(vacancyPoco ?? null);
        }
    }
}
